home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / BORLAND TURBO / GROUPBOX.PAK / GROUPBXX.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  5.1 KB  |  181 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1995 by Borland International, All Rights Reserved
  4. //----------------------------------------------------------------------------
  5. #include <owl/pch.h>
  6. #include <owl/applicat.h>
  7. #include <owl/radiobut.h>
  8. #include <owl/groupbox.h>
  9. #include <owl/static.h>
  10. #include <owl/framewin.h>
  11. #include <cstring.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14.  
  15. const int ID_BCCGROUP     = 100;
  16. const int ID_BCC1         = 101;
  17. const int ID_BCC5         = 102;
  18. const int ID_BCC10        = 103;
  19. const int ID_BCCX         = 104;
  20. const int ID_CPPGROUP     = 110;
  21. const int ID_CPP1         = 111;
  22. const int ID_CPP5         = 112;
  23. const int ID_CPP10        = 113;
  24. const int ID_CPPX         = 114;
  25. const int ID_PLACEBUTTON  = 131;
  26. const int ID_CANCELBUTTON = 132;
  27.  
  28.  
  29. //
  30. // class TOrderGroupBox
  31. // ~~~~~ ~~~~~~~~~~~~~~
  32. class TOrderGroupBox : public TGroupBox {
  33.   public:
  34.     TOrderGroupBox(TWindow*        parent,
  35.                    int             id,
  36.                    const char far* text,
  37.                    int X, int Y, int W, int H,
  38.                    TModule*        module = 0)
  39.     :
  40.       TGroupBox(parent, id, text, X, Y, W, H, module)
  41.     {}
  42.  
  43.     void SelectionChanged(int controlId);
  44.  
  45.     string  itemsOrderedStr;    // stuff ordered.
  46. };
  47.  
  48. //
  49. // SelectionChanged(). Called by check boxes and radio buttons (or your own
  50. // control) when checked/unchecked.
  51. //
  52. void
  53. TOrderGroupBox::SelectionChanged(int controlId)
  54. {
  55.   switch (controlId) {
  56.     case ID_BCC1 :
  57.       itemsOrderedStr = "1 BCC compiler";
  58.       break;
  59.     case ID_BCC5 :
  60.       itemsOrderedStr = "5 BCC compilers";
  61.       break;
  62.     case ID_BCC10 :
  63.       itemsOrderedStr = "10 BCC compilers";
  64.       break;
  65.     case ID_BCCX :
  66.       itemsOrderedStr = "X BCC compilers";
  67.       break;
  68.     case ID_CPP1 :
  69.       itemsOrderedStr = "1 Professional Pack";
  70.       break;
  71.     case ID_CPP5 :
  72.       itemsOrderedStr = "5 Professional Packs";
  73.       break;
  74.     case ID_CPP10 :
  75.       itemsOrderedStr = "10 Professional Packs";
  76.       break;
  77.     case ID_CPPX :
  78.       itemsOrderedStr = "X Professional Packs";
  79.       break;
  80.   };
  81. }
  82.  
  83. //
  84. // class TOrderWindow
  85. // ~~~~~ ~~~~~~~~~~~~
  86. class TOrderWindow : public TWindow {
  87.   public:
  88.     TOrderWindow();
  89.     void PlaceOrder();
  90.     void CancelOrder();
  91.  
  92.     TOrderGroupBox* BCCGroup;
  93.     TOrderGroupBox* CPPGroup;
  94.  
  95.   DECLARE_RESPONSE_TABLE(TOrderWindow);
  96. };
  97.  
  98. DEFINE_RESPONSE_TABLE1(TOrderWindow, TWindow)
  99.   EV_COMMAND(ID_PLACEBUTTON, PlaceOrder),
  100.   EV_COMMAND(ID_CANCELBUTTON, CancelOrder),
  101. END_RESPONSE_TABLE;
  102.  
  103. TOrderWindow::TOrderWindow()
  104. :
  105.   TWindow(0, 0, 0)
  106. {
  107.   Attr.X = 20;
  108.   Attr.Y = 5;
  109.   Attr.W = 380;
  110.   Attr.H = 260;
  111.   new TStatic(this, -1, "Borland C++ now includes an extensive Windows",
  112.     20, 10, 380, 15, 55);
  113.   new TStatic(this, -1, "class library and a complete toolkit for Windows",
  114.     20, 27, 380, 15, 45);
  115.   new TStatic(this, -1, "resource editing.", 20, 44, 380, 15, 55);
  116.   new TStatic(this, -1, "              How many copies would you like?",
  117.     10, 61, 380, 15, 35);
  118.  
  119.   TRadioButton* radio;
  120.   BCCGroup = new TOrderGroupBox(this, ID_BCCGROUP, "BCC Compiler",
  121.     20, 80, 150, 105);
  122.   radio = new TRadioButton(this, ID_BCC1, "1", 30, 100, 40, 17, BCCGroup);
  123.   radio->Attr.Style |= WS_TABSTOP;
  124.   new TRadioButton(this, ID_BCC5, "5", 30, 120, 40, 17, BCCGroup);
  125.   new TRadioButton(this, ID_BCC10, "10", 30, 140, 40, 17, BCCGroup);
  126.   new TRadioButton(this, ID_BCCX, "X", 30, 160, 40, 17, BCCGroup);
  127.   CPPGroup = new TOrderGroupBox(this, ID_CPPGROUP, "Professional Packs",
  128.     189, 80, 150, 105);
  129.   radio = new TRadioButton(this, ID_CPP1, "1", 200, 100, 40, 17, CPPGroup);
  130.   radio->Attr.Style |= WS_TABSTOP;
  131.   new TRadioButton(this, ID_CPP5, "5", 200, 120, 40, 17, CPPGroup);
  132.   new TRadioButton(this, ID_CPP10, "10", 200, 140, 40, 17, CPPGroup);
  133.   new TRadioButton(this, ID_CPPX, "X", 200, 160, 40, 17, CPPGroup);
  134.   new TButton(this, ID_PLACEBUTTON, "PLACE ORDER", 20, 195, 157, 25, FALSE);
  135.   new TButton(this, ID_CANCELBUTTON, "CANCEL ORDER", 181, 195, 157, 25, FALSE);
  136. }
  137.  
  138. //
  139. // PlaceOrder(). Display order.  Display header and items ordered, from group
  140. // box.
  141. //
  142. void
  143. TOrderWindow::PlaceOrder()
  144. {
  145.   string msg;
  146.   string zero("0");   // if nothing ordered.
  147.  
  148.   msg += "BCC: " + (BCCGroup->itemsOrderedStr.is_null() ? zero :
  149.                     BCCGroup->itemsOrderedStr) + "\n";
  150.   msg += "Professional: " + (CPPGroup->itemsOrderedStr.is_null() ? zero :
  151.                              CPPGroup->itemsOrderedStr) + "\n";
  152.   MessageBox(msg.c_str(), "Order", MB_OK);
  153. }
  154.  
  155. void
  156. TOrderWindow::CancelOrder()
  157. {
  158.   MessageBox("Order Cancelled", "Order", MB_OK);
  159. }
  160.  
  161.  
  162. //
  163. // class TOrderApp
  164. // ~~~~~ ~~~~~~~~~
  165. class TOrderApp : public TApplication {
  166.   public:
  167.     TOrderApp() : TApplication() {}
  168.     void InitMainWindow() {
  169.       TFrameWindow* frame = new TFrameWindow(0, "BCC Order Form", new TOrderWindow);
  170.       frame->EnableKBHandler();
  171.       SetMainWindow(frame);
  172.     }
  173. };
  174.  
  175. int
  176. OwlMain(int /*argc*/, char* /*argv*/ [])
  177. {
  178.   TOrderApp app;
  179.   return app.Run();
  180. }
  181.